<template>
  <el-select
    v-model="selectValue"
    v-bind="$attrs"
    multiple
    filterable
    style="width:100%"
    v-on="$listeners"
  >
    <el-option
      v-for="(item,index) in options"
      :key="index"
      :label="item[optionLabel]"
      :value="item[optionValue]"
    />
  </el-select>
</template>

<script>
export default {
  name: 'MultiSelect',
  props: {
    options: {
      type: Array,
      default() {
        return []
      }
    },
    optionLabel: {
      type: String,
      default: 'name'
    },
    optionValue: {
      type: String,
      default: 'id'
    },
    value: {
      type: String
    }
  },
  data() {
    return {
    }
  },
  computed: {
    selectValue: {
      get: function() {
        if (this.value) {
          return this.value.split(',')
        } else {
          return []
        }
      },
      set: function(newValue) {
        this.$emit('update:value', newValue.join(','))
      }
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
